package com.alterzhang.userservice.proxy.jdkproxy;

import com.alterzhang.userservice.proxy.HuangNiu;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MyProxy implements InvocationHandler {

    private HuangNiu person;

    public Object getInstance(HuangNiu target) {
        this.person = target;
        Class clazz = target.getClass();
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), clazz.getInterfaces(), this);

    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("代理开始工作");
        method.invoke(this.person,args);
        return null;
    }
}
